package com.example.satestdemo.controller;

import com.example.satestdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UserController {

    private final UserService service;

    public UserController(@Autowired UserService userService) {
        this.service = userService;
    }

    public static class Req {
        String userName;
        String password;

        public Req(String userName, String password) {
            this.userName = userName;
            this.password = password;
        }
    }

    @PostMapping
    public long register(@RequestBody Req req) {
        return service.register(req.userName, req.password);
    }

    @PostMapping("/login")
    public boolean login(@RequestBody Req req) {
        return service.login(req.userName, req.password);
    }
}
